<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <img src="../img/load.jpg" />
    <!-- <script>
        let num=0;
        for(let i=0;i<3;i++){
            //创建图片对象
            let img=new Image()
            //使用
            img.src="../img/"+(i+1)+".jpg"
            img.onload=()=>{
                num++
                if(num==3){
                    console.log("加载成功");
                }
                console.log(img.src);
            }
        }
    </script> -->


    <script>
        //使用Promise
        var num
        var arr = []
        for (let i = 0; i < 3; i++) {
            let p1 = new Promise((resovle, reject) => {

                //创建图片对象
                let img = new Image()
                //使用
                img.src = "../img/" + (i + 1) + ".jpg"
                img.onload = () => {
                    resovle(img)
                }

            })
            arr.push(p1)
        }
        console.log(arr)
        //把多个请求，请求完成后才输出
        let pAll = Promise.all(arr)
        pAll.then((res) => {
            console.log(res, "加载成功")
        })

    </script>
</body>

</html>